package utility;

import java.util.Comparator;

public class Pair<P, Q> {

	private P p;
	private Q q;
	
	public Pair(P p, Q q) {
		this.p = p;
		this.q = q;
	}
	
	public P first() {
		return p;
	}
	
	public Q second() {
		return q;
	}
	
	public void first(P p) {
		this.p = p;
	}
	
	public void second(Q q) {
		this.q = q;
	}
	
	
	@Override
	public String toString() {
		return "("+p+","+q+")";
	}

	public static class FirstComparator<P extends Comparable<P>,Q > implements Comparator<Pair<P,Q>> {

		@Override
		public int compare(Pair<P, Q> o1, Pair<P, Q> o2) {
			return o1.first().compareTo(o2.first());
		}
		
	}

	
	public static class SecondComparator<P,Q extends Comparable<Q>> implements Comparator<Pair<P,Q>> {

		@Override
		public int compare(Pair<P, Q> o1, Pair<P, Q> o2) {
			return o1.second().compareTo(o2.second());
		}
		
	}

	public static class SecondDescendingComparator<P,Q extends Comparable<Q>> implements Comparator<Pair<P,Q>> {

		@Override
		public int compare(Pair<P, Q> o1, Pair<P, Q> o2) {
			return -o1.second().compareTo(o2.second());
		}
		
	}
	
}
